<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp"%>
<%
	//查询所有的科室主任列表
	
	//查询所有主任医师
	List<Map> lis = QBuilder.db("basedb").queryHql("select new map(id as id ,ks_id as ks_id , ks_mc as ks_mc) from YY_ZGBMK where zc_id = '01' and ks_mc != '' ");
	Map msMap = new HashMap();
	//去重并随机取出一个主任的id
	for(Map map : lis){
		//String id = "";
		msMap.put(map.get("ks_id"),map.get("id").toString() +"");
	}
	
	//获取所有科室
	List<Map> deptList = QBuilder.db("basedb").queryHql("select new map(id as id , name as name ) from his_dept where 1=1 and yjks_id != 1010 and yydm='02' and id != '' ");
			
	List<Map> resList = new ArrayList<Map>();
	String exid = "";//存在的id
	for(Map map : deptList){
		
		String deptId =  map.get("id") == null || msMap.get(map.get("id").toString()) == null ? "-1" : msMap.get(map.get("id").toString()).toString();
		
		map.put("empId",deptId);
		if(!deptId.equals("-1") && exid.indexOf(deptId) == -1){//未找到
		
			resList.add(map);
			
		}
	}
	
	//获取所有科室
	List<Map> deptList2 = QBuilder.db("basedb").queryHql("select new map(id as id , name as name ) from his_dept where 1=1 and yydm='01' and id != '' ");
	
	List<Map> resList2 = new ArrayList<Map>();
	String exid2 = "";//存在的id
	for(Map map : deptList2){
		
		String deptId =  map.get("id") == null || msMap.get(map.get("id").toString()) == null ? "-1" : msMap.get(map.get("id").toString()).toString();
		
		map.put("empId",deptId);
		if(!deptId.equals("-1") && exid2.indexOf(deptId) == -1){//未找到
		
			resList2.add(map);
			
		}
	}
	
	Map resMap = new HashMap();
	resMap.put("list_02",resList);
	resMap.put("list_01",resList2);
	
	Message msg = new Message();
	msg.put("errcode",0);
	msg.put("data",resMap);
	
	out.println(msg);
%>